<?php
class Monitor extends CI_Controller{
	
	function __construct(){
		parent::__construct();
		$this->is_logged_in();
	}
	
	function index(){
		
		
		$data['main_content'] = 'monitor_index_view';
		$this->load->view('includes/template', $data);
		
		
	}

	function monitor_area(){
		//$this->load->view('monitor_view');
		$this->load->library('table');
		$tmpl = array( 'table_open'  => '<table class="art-article" border="0" cellspacing="0" cellpadding="0">' );
		$this->table->set_template($tmpl);
		$this->table->set_heading('REFERENCE ID','FIRSTNAME','LASTNAME','MIDDLENAME','GENDER','CIVIL STATUS','DATE IN','STATUS');
		$this->load->model('membership_model');
		$data['records'] = $this->membership_model->getActive_member();
		
		$data['main_content'] = 'monitor_view';
		$this->load->view('includes/template', $data);
	}
	
	function is_logged_in(){
		$is_logged_in = $this->session->userdata('is_logged_in');
		if(!isset($is_logged_in) || $is_logged_in != true){
			//$data['main_content'] = 'no_permission_view';
			//$this->load->view('includes/template', $data);
			redirect('login');
		}
	}
	
	function create_member(){
		
		$this->form_validation->set_rules('reference_id','Reference ID','required');
		$this->form_validation->set_rules('firstname','Firstname','required');
		$this->form_validation->set_rules('middlename','Middlename','required');
		$this->form_validation->set_rules('lastname','Lastname','required');
		$this->form_validation->set_rules('dob','Date of Birth','required');
		
		if($this->form_validation->run() ==  FALSE){
			$this->member_add_new();
		}else{
			$this->load->model('membership_model');
			if($q = $this->membership_model->create_member()){
				$this->member_add_new();
			}
		}
		
	
	}
	
	function view_members(){
		$this->load->library('table');
		$tmpl = array( 'table_open'  => '<table class="art-article" border="0" cellspacing="0" cellpadding="0">' );
		$this->table->set_template($tmpl);
		$this->table->set_heading('REFERENCE ID','FIRSTNAME','LASTNAME','MIDDLENAME','GENDER','CIVIL STATUS','DATE IN','STATUS');
		$this->load->model('membership_model');
		$data['records'] = $this->membership_model->getActive_member();
		$data['main_content'] = 'member_list_view';
		$this->load->view('includes/template', $data);
		
	
	}
	
	function search_active_member(){
		if($this->input->post('search_criteria')){
			$this->load->library('table');
			$tmpl = array( 'table_open'  => '<table class="art-article" border="0" cellspacing="0" cellpadding="0">' );
			$this->table->set_template($tmpl);
			$this->table->set_heading('REFERENCE ID','FIRSTNAME','LASTNAME','MIDDLENAME','GENDER','CIVIL STATUS','DATE IN','STATUS');
			$this->load->model('membership_model');
			$data['records'] = $this->membership_model->search_active_member();
			$data['main_content'] = 'member_list_view';
			$this->load->view('includes/template', $data);
		
			
		}else{
			redirect('monitor/monitor_area');
		}
	
	}
	
	function member_add_new(){
		$data['main_content'] = 'member_add_new_view';
		$this->load->view('includes/template', $data);
	
	}
	
	
}